package tests;

import static org.junit.Assert.*;

import org.junit.Test;

import coreSimulation.Passenger;
import coreSimulation.Baggage;

public class PassengerTest {

	Passenger p;

	@Test
	public void testGetName() {
		p = new Passenger("Bob Dobbs", "SA-12345678");
		assertEquals("The getName() method failed for the Passenger class",
				"Bob Dobbs", p.getName());
	}

	@Test
	public void testGetBookingRef() {
		p = new Passenger("Bob Dobbs", "SA-12345678");
		assertEquals(
				"The getBookingRef() method failed for the Passenger class",
				"SA-12345678", p.getBookingRef());
	}

	@Test
	public void testSetGetBaggage() { // This method tests both getBaggage and
										// setBaggage for the Passenger class
		p = new Passenger("Bob Dobbs", "SA-12345678");
		Baggage bag1 = new Baggage(10, 10, 10, 10);
		p.addBaggage(bag1);

		Baggage bag2 = p.getBaggage();

		assertEquals("getBaggage method failed", bag1, bag2);
	}

	@Test(expected = IllegalStateException.class)
	public void testPassengerNoName() {
		p = new Passenger("", "SA-12345678"); // name parameter length 0

	}

	@Test(expected = IllegalStateException.class)
	public void testPassengerInvalidRef1() {
		p = new Passenger("John Smith", "SA-1234"); // numeric part of
													// booking ref too short

	}

	@Test(expected = IllegalStateException.class)
	public void testPassengerInvalidRef2() {
		p = new Passenger("John Smith", "SA-123456789"); // numeric part of
															// booking ref too
															// long

	}

	@Test(expected = IllegalStateException.class)
	public void testPassengerInvalidRef3() {
		p = new Passenger("John Smith", "SA-X23456789"); // numeric part of
															// booking
															// incorrect
															// number format
	}

	@Test(expected = IllegalStateException.class)
	public void testPassengerInvalidRef4() {
		p = new Passenger("John Smith", "XX-12345678"); // booking ref
														// prefix incorrect

	}

	@Test
	public void testCompareTo() {
		// Two passengers with the same booking ref
		Passenger p1 = new Passenger("Erica Eller", "SA-55705175");
		Passenger p2 = new Passenger("Dennis Dillow", "SA-55705175");

		assertTrue(p1.compareTo(p2) == 0);
	}

	@Test
	public void testEquals() {
		// Two passengers with the same booking ref
		Passenger p1 = new Passenger("Erica Eller", "SA-55705175");
		Passenger p2 = new Passenger("Dennis Dillow", "SA-55705175");

		assertTrue(p1.equals(p2));
	}

	@Test
	public void testHashCode() {
		// Two passengers with the same booking ref
		Passenger p1 = new Passenger("Erica Eller", "SA-55705175");
		Passenger p2 = new Passenger("Dennis Dillow", "SA-55705175");

		assertEquals(p1.hashCode(), p2.hashCode());
	}
	
	@Test
	public void testExcessCharges(){
		Passenger p = new Passenger("John Smith", "SA-12345678");
		p.addExcessCharge(99.99);
		assertEquals(p.getExcessCharges(), 99.99, 0);
	}


}
